#define  _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int prev_min = prices[0], ans = 0, size = prices.size();
        for (int i = 1; i < size; i++)
        {
            if (prices[i] <= prev_min) prev_min = prices[i];
            else ans = max(ans, prices[i] - prev_min);
        }
        return ans;
    }
};